﻿Imports System.Data
Imports System.Data.Odbc
Module dataArriendo

    Public idCRArriendo As Integer
    Public Function sumaArriendo(ByVal arriendo1 As Integer, ByVal arriendo2 As Integer, ByVal arriendo3 As Integer, ByVal arriendo4 As Integer) As Long
        Return CLng(arriendo1 + arriendo2 + arriendo3 + arriendo4)
    End Function

    Sub datosCBPagosArriendo()

        conectar()
        Dim dt2 As New DataTable

        cmd = New OdbcCommand("SELECT ID, Nombre FROM  tformasdepago", con)
        dr = cmd.ExecuteReader
        'executing the command and assigning it to connection 

        dt2.Load(dr, LoadOption.OverwriteChanges)
        With frmArriendo.cbFormasDePago
            .DataSource = dt2
            .DisplayMember = dt2.Columns.Item(1).Caption
            .ValueMember = dt2.Columns.Item(0).Caption
        End With

        desconectar()

    End Sub


    Sub ingresaPagoArriendo(ByVal fecha As String, ByVal formaPago As Integer, ByVal documento As String, ByVal total As Integer, ByVal pagadoPor As String, ByVal pvalor1 As Integer, ByVal pvalor2 As Integer, ByVal pvalor3 As Integer, ByVal pvalor4 As Integer, ByVal obs As String)
        Dim fa As Integer
        Dim lastInsertId As Integer
        Try


            conectar()
            cmd.Connection = con
            cmd.CommandText = "INSERT INTO tPagosRecibidos (Fecha,IDFormasDePago,NumeroDocumento,Total,PagadoPor,Comentarios) VALUES ('" + fecha + "','" & formaPago & "','" + documento + "','" & total & "','" + pagadoPor + "','" + obs + "')"
            cmd.CommandType = CommandType.Text
            fa = cmd.ExecuteNonQuery
            desconectar()
            If fa > 0 Then
                ' EXTRAER ID Ingresado
                conectar()
                cmd.Connection = con
                cmd.CommandText = "SELECT MAX(ID) FROM tPagosRecibidos"
                cmd.CommandType = CommandType.Text
                dr = cmd.ExecuteReader
                If dr.HasRows Then
                    dr.Read()
                    lastInsertId = dr(0)
                    idCRArriendo = lastInsertId

                End If
                dr.Close()
                desconectar()
                fa = 0
                conectar()
                cmd.Connection = con
                cmd.CommandText = "INSERT INTO tarriendo (Fecha,PagadoPor,IDLogin,IDPagoRecibido,ValorSede,ValorLocales,ValorGarantia,ValorOtros) VALUES ('" + fecha + "','" + pagadoPor + "','" & usuarioID & "', '" & lastInsertId & "','" & pvalor1 & "','" & pvalor2 & "','" & pvalor3 & "','" & pvalor4 & "')"
                cmd.CommandType = CommandType.Text
                fa = cmd.ExecuteNonQuery
                If fa > 0 Then
                    With frmArriendo
                        .txtNombre.Clear()
                        .txtNombre.Focus()

                        .txtSede.Text = "0"
                        .txtLocal.Text = "0"
                        .txtGarantia.Text = "0"
                        .txtPago1.Text = "0"
                        .txtTotal.Text = "0"
                        .txtNumeroDocumento.Clear()
                        .txtObservaciones.Clear()


                    End With

                End If
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub
End Module
